﻿/*************************************************************************
 * 
 * Filename :catetree
 * 
 * steven hu   2010/3/12 9:32:25
 *  
 * http://www.cnblogs.com/huxj
 *   
 * 
 * Change History:
 * 
 * 
**************************************************************************/



using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hxj.Common;
using Hxj.Data;
using Hxj.Data.Common;
using Hxj.Web;
using RicciWebsite.Model;
using System.Data;

namespace RicciWebsite.admin.products
{
    public partial class catetree : RicciWebsite.Pages.AdminPage
    {
        /// <summary>
        /// 类别
        /// </summary>
        protected int type = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["type"] == "1")
                type = 1;


            catelist = RicciDatabase.Default.From<data_products_categories>().Where(data_products_categories._.catetype == 1).ToList();

            TreeNode rootNode = new TreeNode("根目录", "");
            rootNode.SelectAction = TreeNodeSelectAction.Expand;
            treecategory.Nodes.Add(rootNode);

            
            bindTree(rootNode, new Guid().ToString());

            treecategory.ExpandDepth = 2;
        }


        void bindTree(TreeNode node, string parentid)
        {
            List<data_products_categories> findcatelist = catelist.FindAll(delegate(data_products_categories catein) { return string.Compare(catein.ppcid, parentid, true) == 0; });

            foreach (data_products_categories categoryModel in findcatelist)
            {
                TreeNode childNode = new TreeNode(categoryModel.pcname, categoryModel.pcid);
                childNode.Target = "maincate";
                if (type == 0)
                {
                    childNode.NavigateUrl = "category.aspx?pcid=" + categoryModel.pcid;
                }
                else
                {
                    childNode.NavigateUrl = "productlist.aspx?pcid=" + categoryModel.pcid;
                }

                node.ChildNodes.Add(childNode);

                bindTree(childNode, categoryModel.pcid);

            }

        }


        List<data_products_categories> catelist = new List<data_products_categories>();
    }
}
